﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【备绳维保】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto备绳维保
    /// </summary>
    public abstract class AutoStockWireropeKeepMapping : BaseMapping<StockWireropeKeep, StockWireropeKeepModel, StockWireropeKeepFilterModel>
    {
        public AutoStockWireropeKeepMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override StockWireropeKeepModel Entity2Model(StockWireropeKeep entity)
        {
            StockWireropeKeepModel model = new StockWireropeKeepModel();

            model.StockWireropeKeepID = entity.StockWireropeKeepID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Code = entity.Code;
            model.StockID = entity.StockID;
            model.CompanyName = entity.CompanyName;
            model.UserName = entity.UserName;
            model.DoDate = entity.DoDate;
            model.Remark = entity.Remark;
            model.Pic_ImgsList = entity.Pic_Imgs.GetFileList();
            model.Attr_ImgsList = entity.Attr_Imgs.GetFileList();
            model.Status = entity.Status;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;
            model.SubmitUserID = entity.SubmitUserID;
            model.SubmitUserName = entity.SubmitUserName;
            model.SubmitDate = entity.SubmitDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override StockWireropeKeep Model2Entity(StockWireropeKeepModel model)
        {
            StockWireropeKeep entity = new StockWireropeKeep();

            entity.StockWireropeKeepID = model.StockWireropeKeepID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Code = model.Code;
            entity.StockID = model.StockID;
            entity.CompanyName = model.CompanyName;
            entity.UserName = model.UserName;
            entity.DoDate = model.DoDate;
            entity.Remark = model.Remark;
            entity.Pic_Imgs = model.Pic_ImgsList.GetFileString();
            entity.Attr_Imgs = model.Attr_ImgsList.GetFileString();
            entity.Status = model.Status;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;
            entity.SubmitUserID = model.SubmitUserID;
            entity.SubmitUserName = model.SubmitUserName;
            entity.SubmitDate = model.SubmitDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<StockWireropeKeep> FilterModel2Where(StockWireropeKeepFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._StockWireropeKeepID.HasValue)
            {
                where = where.And(x => x.StockWireropeKeepID == filterModel._StockWireropeKeepID.Value);
            }
            if (filterModel._StockWireropeKeepIDs.IsNotEmpty() && filterModel._StockWireropeKeepIDs.Count > 0)
            {
                where = where.And(x => filterModel._StockWireropeKeepIDs.Contains(x.StockWireropeKeepID));
            }
            if (filterModel._NotStockWireropeKeepIDs.IsNotEmpty() && filterModel._NotStockWireropeKeepIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotStockWireropeKeepIDs.Contains(x.StockWireropeKeepID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //编码
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //单据详细
            if (filterModel._StockID.HasValue)
            {
                where = where.And(x => x.StockID == filterModel._StockID.Value);
            }
            if (filterModel._StockIDs.IsNotEmpty() && filterModel._StockIDs.Count > 0)
            {
                where = where.And(x => filterModel._StockIDs.Contains(x.StockID));
            }
            if (filterModel._NotStockIDs.IsNotEmpty() && filterModel._NotStockIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotStockIDs.Contains(x.StockID));
            }

            //实施单位
            if (!string.IsNullOrEmpty(filterModel._CompanyName))
            {
                where = where.And(x => x.CompanyName.Contains(filterModel._CompanyName));
            }
            if (!string.IsNullOrEmpty(filterModel._CompanyNameEqual))
            {
                where = where.And(x => x.CompanyName == filterModel._CompanyNameEqual);
            }

            //实施人员
            if (!string.IsNullOrEmpty(filterModel._UserName))
            {
                where = where.And(x => x.UserName.Contains(filterModel._UserName));
            }
            if (!string.IsNullOrEmpty(filterModel._UserNameEqual))
            {
                where = where.And(x => x.UserName == filterModel._UserNameEqual);
            }

            //实施日期
            if (filterModel._DoDate.HasValue)
            {
                where = where.And(x => x.DoDate == filterModel._DoDate.Value);
            }
            if (filterModel._DoDate_Begin.HasValue)
            {
                where = where.And(x => x.DoDate >= filterModel._DoDate_Begin.Value);
            }
            if (filterModel._DoDate_End.HasValue)
            {
                where = where.And(x => x.DoDate < filterModel._DoDate_End.Value.AddDays(1));
            }

            //状态
            if (filterModel._Status.HasValue)
            {
                where = where.And(x => x.Status == filterModel._Status.Value);
            }
            if (filterModel._Statuss.IsNotEmpty() && filterModel._Statuss.Count > 0)
            {
                where = where.And(x => filterModel._Statuss.Contains(x.Status));
            }
            if (filterModel._NotStatuss.IsNotEmpty() && filterModel._NotStatuss.Count > 0)
            {
                where = where.And(x => !filterModel._NotStatuss.Contains(x.Status));
            }

            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            //提交人姓名
            if (!string.IsNullOrEmpty(filterModel._SubmitUserName))
            {
                where = where.And(x => x.SubmitUserName.Contains(filterModel._SubmitUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._SubmitUserNameEqual))
            {
                where = where.And(x => x.SubmitUserName == filterModel._SubmitUserNameEqual);
            }

            //提交日期
            if (filterModel._SubmitDate.HasValue)
            {
                where = where.And(x => x.SubmitDate == filterModel._SubmitDate.Value);
            }
            if (filterModel._SubmitDate_Begin.HasValue)
            {
                where = where.And(x => x.SubmitDate >= filterModel._SubmitDate_Begin.Value);
            }
            if (filterModel._SubmitDate_End.HasValue)
            {
                where = where.And(x => x.SubmitDate < filterModel._SubmitDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

